package com.yinhai.redis.cluster.monitors;

import java.util.List;

import org.apache.zookeeper.WatchedEvent;

import com.yinhai.redis.cluster.event.ClusterEvent;
import com.yinhai.redis.cluster.event.EventBus;
import com.yinhai.redis.cluster.model.ShardHolder;

public class LivesNodeMonitor extends ChildrenMonitor {
	
	private List<ShardHolder> holders;

	public List<ShardHolder> getHolders() {
		return holders;
	}

	public void setHolders(List<ShardHolder> holders) {
		this.holders = holders;
	}

	@Override
	protected void doProcess(WatchedEvent event) {
		ClusterEvent e=new ClusterEvent();
		e.setTarget(this);
		for(ShardHolder holder:holders){
			if(holder.getInfo().getName().equals(event.getPath().substring(event.getPath().lastIndexOf("/"), event.getPath().length()))){
				e.setData(holder);
				break;
			}
		}
		EventBus.getInstance().publishEvent(e);
	}

}
